//二次封装axios


import axios from "axios";
import nProgress from "nprogress";
import 'nprogress/nprogress.css'

const ajax = axios.create({
  timeout: 5000,
  baseURL:'/api'
})

// 请求拦截器
ajax.interceptors.request.use((config) => {
  nProgress.start()
  return config
})

// 响应拦截器
ajax.interceptors.response.use(() => {
  response => {
    nProgress.done()
    return response.data
   
  },
   error => {
      // 请求失败返回一个pending状态的promise 中断
     nProgress.done()
     console.log(error)
     return new Promise(()=>{})
      
  }
})


export default ajax

